package com.huang.springbootthymeleafshiro.service.impl;


import com.huang.springbootthymeleafshiro.bean.Pers;
import com.huang.springbootthymeleafshiro.bean.User;
import com.huang.springbootthymeleafshiro.dao.UserDao;
import com.huang.springbootthymeleafshiro.service.UserService;
import com.huang.springbootthymeleafshiro.utils.SaltUtils;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceimpl implements UserService {
    @Autowired
   private UserDao dao;
    @Override
    public void register(User user) {
        String pwd = user.getPwd();
        String salt = SaltUtils.getSalt(8);
        Md5Hash md5Hash=new Md5Hash(pwd,salt,1024);
        String s = md5Hash.toHex();
        user.setPwd(s);
        user.setSalt(salt);
        dao.save(user);
    }

    @Override
    public User findbyname(String name) {
        return dao.findbyUser(name);
    }

    @Override
    public User findRolebyname(String name) {
        User user = dao.findRolebyname(name);

        return user;
    }

    @Override
    public List<Pers> findPersbyid(String id) {
        List<Pers> persList = dao.findPersbyid(id);
        return persList;
    }
}
